#include "CryptStream.h"

static const uint32_t key[4] = {0x54453708, 0x1EBB247B, 0xAD211230, 0x12994963};

void printbuffer(CryptStream &s) {
  Serial.print("output buffer: ");
  if (s.overflow()) { Serial.println("OVERFLOW!"); return; }
  if (!s.available()) { Serial.println("not ready"); return; }
  while (s.available()) { Serial.print(s.read(), HEX);Serial.print(" "); }
  Serial.println();
}


void setup(){
  
  Serial.begin(9600);
  
  CryptStream s = CryptStream(key);
  
  uint32_t myvar=100;

  Serial.println("input: uint32_t (tot: 4 bytes)");
  s.write(myvar);
  printbuffer(s); // not ready, incomplete buffer

  Serial.println("input: 7 bytes const char (tot: 11 bytes)");
  s.writearray("hello!");
  printbuffer(s); // will print one encrypted block of 8 bytes
                  // input buffer still contains 3 bytes, i.e. "o!<NULL>"
  
  Serial.println("input: finalize stream");
  s.finalize(); // will pad the input stream with 5 more bytes to fill the block
  printbuffer(s); // will print one encrypted block ("o!<NULL><PAD><PAD><PAD><PAD><PAD>")

}

void loop(){
}

